import { Vec3Util } from 'db://app-game/core/utils/Vec3Util';
import { AnimatorStateLogic } from 'db://app-game/libs/animator/core/AnimatorStateLogic';
import { ecs } from 'db://app-game/libs/ecs/ECS';
import { BowEffects } from '../../../../effects/entity/BowEffects';
import { Role } from '../../../Role';
import { AnimationEventHandler } from '../AnimationEventHandler';

/** 射箭释放状态 */
export class RoleStateRelease extends AnimatorStateLogic {
  /** 角色 */
  private role: Role = null!;
  private animator: AnimationEventHandler = null!;

  constructor(role: Role, animator: AnimationEventHandler) {
    super();
    this.role = role;
    this.animator = animator;
  }

  onEntry() {
    // 1.释放弓箭
    const bowEffects = ecs.getEntity<BowEffects>(BowEffects);

    // 2.获取角色节点方向
    const eulerAngles = this.role.RoleView.node.getChildByName('body').eulerAngles;
    const yRotation = eulerAngles.y;
    const direction = Vec3Util.angleToVec3(yRotation);
    const params = {
      id: 0,
      pos: this.role.RoleView.node.position,
      direction,
      speedOfMove: 1000,
      moveTime: 10,
    };
    bowEffects.load(params);
  }
}
